﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using wojilu.Apps.Qycms.Domain;
using wojilu.IO;
using wojilu.Members.Interface;
using wojilu.Members.Sites.Domain;
using wojilu.Members.Sites.Service;
using wojilu.Members.Users.Domain;
using wojilu.Members.Users.Interface;
using wojilu.Members.Users.Service;
using wojilu.Net;
using wojilu.Web.Controller.Admin.Qycms;
using wojilu.Web.Controller.Common;
using wojilu.Web.Mvc;
using wojilu.Web.Mvc.Attr;
using YBBYunQi;

namespace wojilu.Web.Controller.Admin
{
    public class QycmsController : BaseController
    {
        private String loadfun { get; set; }
        private String TabTitle { get; set; }
        private String TabUrl { get; set; }
        private Int32 menuid { get; set; }
        private String queryname { get; set; }
        public virtual IUserService userService { get; set; }
        public virtual IAdminLogService<SiteLog> logService { get; set; }

        public QycmsController()
        {
            userService = new UserService();
            logService = new SiteLogService();
        }

        [HttpGet]
        public virtual void Index()
        {
            var lngs = DefaultLng;
            if (lngs.StrIsNullOrEmpty())
            {
                var default_lng = configsService.GetValue("default_lng");
                ctx.web.CookieSet("Lngs", default_lng);
            }
            loadfun = ctx.Get("loadfun");
            menuid = ctx.GetInt("menuid");
            queryname = ctx.url.Query;
            TabTitle = ctx.Get("menuname_title");
            switch (loadfun)
            {
                case "skinlist":
                case "menulinklist":
                case "loglist":
                case "languagelist":
                case "lanpacklist":
                case "adverttypelist":
                case "sitelist":
                case "mangerlist":
                case "grouplist":
                case "modellist":
                case "modelattlist":
                case "acmessagelist":
                case "callinglist":
                case "bbstypelist":
                case "bbsmainlist":
                case "formlist":
                case "messlist":
                case "formattlist":
                case "fileadminlist":
                    TabUrl = to(Admin_Tab_List) + queryname;
                    run(Admin_Tab_Center);
                    break;

                case "recomlist":
                case "menulinkclist":
                case "advertlist":
                case "articlelist":
                case "subjectlist":
                    TabUrl = to(Admin_Tab_List) + queryname;
                    run(Admin_Tab);
                    break;

                case "syssetting":
                    TabUrl = to(new HomeController().SysSetting) + queryname;
                    run(Admin_Tab_Editor);
                    break;

                case "createindex":
                    TabUrl = to(new CreateController().CreateIndex) + queryname;
                    run(Admin_Tab_Editor);
                    break;

                case "createtype":
                    TabUrl = to(new CreateController().CreateType) + queryname;
                    run(Admin_Tab_Editor);
                    break;

                case "createdoc":
                    TabUrl = to(new CreateController().CreateDoc) + queryname;
                    run(Admin_Tab_Editor);
                    break;

                case "templatelist":
                    TabUrl = to(Admin_Tab_List_Page) + queryname;
                    run(Admin_Tab_Center);
                    break;

                case "typelist":
                    TabUrl = to(Admin_Tab_List_Page) + queryname;
                    run(Admin_Tab);
                    break;

                case "":
                default:
                    TabTitle = "网站管理平台";
                    TabUrl = to(new HomeController().Admin_Center) + "?";
                    run(Admin_Tab_Center);
                    break;
            }
        }

        [NonVisit]
        public virtual void Admin_Tab()
        {
            set("tabtitle", TabTitle);
            set("taburl", TabUrl);
            set("logout", to(new AdminController().Logout));
            set("clickmenubotton", "$(\"#clickmenubotton li span\").click(function(){$(this).addClass(\"bgmenuhove2\");$(this).parent().find(\"ul.subnav\").slideDown('fast').show();$(this).parent().hover(function(){},function(){$(this).parent().find(\"ul.subnav\").fadeOut('fast');$(this).parent().find(\"span\").removeClass(\"bgmenuhove2\")})});$(\".srcolcontent\").jscroll({W:\"15px\",BgUrl:\"url(" + sys.Path.Img + "ybb/images/s_bg.gif)\",Bg:\"right 0 repeat-y\",Bar:{Bd:{Out:\"#bcbcbc\",Hover:\"#ccc\"},Bg:{Out:\"-45px 0 repeat-y\",Hover:\"-58px 0 repeat-y\",Focus:\"-71px 0 repeat-y\"}},Btn:{btn:true,uBg:{Out:\"0 0\",Hover:\"-15px 0\",Focus:\"-30px 0\"},dBg:{Out:\"0 -15px\",Hover:\"-15px -15px\",Focus:\"-30px -15px\"}},Fn:function(){}});$(\"#centerhidden\").toggle(function(){scrolclear()},function(){scrolopen()});");
            set("esptabkey", "var esptabkey={showLoader:function(){$('#divMainLoader').css('display','none')},removeLoader:function(){$('#divMainLoader').css('display','none')},buildTree:function(){$('.functree li').each(function(){if($(this).is(':has(ul)')){$(this).addClass('collapse')}if($(this).next().is('li')||$(this).next().is('ul')){$(this).css({borderLeft:'dashed 1px #dedede'})}});$('li.collapse>span').click(function(){$(this).next('ul').slideToggle('fast',function(){if($(this).parent().hasClass('collapse')){$(this).parent().removeClass('collapse').addClass('expand')}else{$(this).parent().removeClass('expand').addClass('collapse')}})});$('p.tabclick').css({'cursor':'pointer'}).hover(function(){$(this).css({'color':'#3de','text-decoration':'none'})},function(){$(this).css({'color':'#000','text-decoration':'none'})}).click(function(){var dataLink=$(this).attr('dataLink')+\"&freshid=\"+Math.random();$.fn.jerichoTab.addTab({tabFirer:$(this),title:$(this).text(),closeable:true,iconImg:$(this).attr('iconImg'),data:{dataType:$(this).attr('dataType'),dataLink:dataLink}}).showLoader().loadData()})},buildTabpanel:function(){$.fn.initJerichoTab({renderTo:'.divRight',uniqueId:'myJerichoTab',contentCss:{'height':$('.divRight').height()-40},tabs:[{closeable:false,iconImg:'',title:tabtitle,data:{dataType:'iframe',dataLink:tabdataLink}}],activeTabIndex:0,loadOnce:true})}}");
            set("jsstr", "sdmenuvol();esptabkey.buildTree();esptabkey.buildTabpanel();esptabkey.removeLoader();");
            SetPublic();
            set("top", loadHtml(Top));
            set("tabbotton", loadHtml(TabBotton));
        }

        [NonVisit]
        public virtual void Admin_Tab_Center()
        {
            set("tabtitle", TabTitle);
            set("taburl", TabUrl);
            set("logout", to(new AdminController().Logout));
            set("clickmenubotton", "$(\"#clickmenubotton li span\").click(function(){$(this).addClass(\"bgmenuhove2\");$(this).parent().find(\"ul.subnav\").slideDown('fast').show();$(this).parent().hover(function(){},function(){$(this).parent().find(\"ul.subnav\").fadeOut('fast');$(this).parent().find(\"span\").removeClass(\"bgmenuhove2\")})});$(\".srcolcontent\").jscroll({W:\"15px\",BgUrl:\"url(" + sys.Path.Img + "ybb/images/s_bg.gif)\",Bg:\"right 0 repeat-y\",Bar:{Bd:{Out:\"#bcbcbc\",Hover:\"#ccc\"},Bg:{Out:\"-45px 0 repeat-y\",Hover:\"-58px 0 repeat-y\",Focus:\"-71px 0 repeat-y\"}},Btn:{btn:true,uBg:{Out:\"0 0\",Hover:\"-15px 0\",Focus:\"-30px 0\"},dBg:{Out:\"0 -15px\",Hover:\"-15px -15px\",Focus:\"-30px -15px\"}},Fn:function(){}});$(\"#centerhidden\").toggle(function(){scrolclear()},function(){scrolopen()});");
            set("esptabkey", "var esptabkey={showLoader:function(){$('#divMainLoader').css('display','none')},removeLoader:function(){$('#divMainLoader').css('display','none')},buildTree:function(){$('.functree li').each(function(){if($(this).is(':has(ul)')){$(this).addClass('collapse')}if($(this).next().is('li')||$(this).next().is('ul')){$(this).css({borderLeft:'dashed 1px #dedede'})}});$('li.collapse>span').click(function(){$(this).next('ul').slideToggle('fast',function(){if($(this).parent().hasClass('collapse')){$(this).parent().removeClass('collapse').addClass('expand')}else{$(this).parent().removeClass('expand').addClass('collapse')}})});$('p.tabclick').css({'cursor':'pointer'}).hover(function(){$(this).css({'color':'#3de','text-decoration':'none'})},function(){$(this).css({'color':'#000','text-decoration':'none'})}).click(function(){var dataLink=$(this).attr('dataLink')+\"&freshid=\"+Math.random();$.fn.jerichoTab.addTab({tabFirer:$(this),title:$(this).text(),closeable:true,iconImg:$(this).attr('iconImg'),data:{dataType:$(this).attr('dataType'),dataLink:dataLink}}).showLoader().loadData()})},buildTabpanel:function(){$.fn.initJerichoTab({renderTo:'.divRight',uniqueId:'myJerichoTab',contentCss:{'height':$('.divRight').height()-40},tabs:[{closeable:false,iconImg:'',title:tabtitle,data:{dataType:'iframe',dataLink:tabdataLink}}],activeTabIndex:0,loadOnce:true})}}");
            set("jsstr", "sdmenuvol();esptabkey.buildTree();esptabkey.buildTabpanel();esptabkey.removeLoader();");
            SetPublic();
            set("top", loadHtml(Top));
        }

        [NonVisit]
        public virtual void Admin_Tab_Editor()
        {
            set("tabtitle", TabTitle);
            set("taburl", TabUrl);
            set("logout", to(new AdminController().Logout));
            set("jsstr", "sdmenuvol();esptabkey.buildTree();esptabkey.buildTabpanel();esptabkey.removeLoader();");
            set("esptabkey", "var esptabkey={showLoader:function(){$('#divMainLoader').css('display','none')},removeLoader:function(){$('#divMainLoader').css('display','none')},buildTree:function(){$('.functree li').each(function(){if($(this).is(':has(ul)')){$(this).addClass('collapse')}if($(this).next().is('li')||$(this).next().is('ul')){$(this).css({borderLeft:'dashed 1px #dedede'})}});$('li.collapse>span').click(function(){$(this).next('ul').slideToggle('fast',function(){if($(this).parent().hasClass('collapse')){$(this).parent().removeClass('collapse').addClass('expand')}else{$(this).parent().removeClass('expand').addClass('collapse')}})});$('p.tabclick').css({'cursor':'pointer'}).hover(function(){$(this).css({'color':'#3de','text-decoration':'none'})},function(){$(this).css({'color':'#000','text-decoration':'none'})}).click(function(){var dataLink=$(this).attr('dataLink')+\"&freshid=\"+Math.random();$.fn.jerichoTab.addTab({tabFirer:$(this),title:$(this).text(),closeable:true,iconImg:$(this).attr('iconImg'),data:{dataType:$(this).attr('dataType'),dataLink:dataLink}}).showLoader().loadData()})},buildTabpanel:function(){$.fn.initJerichoTab({renderTo:'.divRight',uniqueId:'myJerichoTab',contentCss:{'height':$('.divRight').height()-40},tabs:[{closeable:false,iconImg:'',title:tabtitle,data:{dataType:'iframe',dataLink:tabdataLink}}],activeTabIndex:0,loadOnce:true})}}");
            set("clickmenubotton", "$(\"#clickmenubotton li span\").click(function(){$(this).addClass(\"bgmenuhove2\");$(this).parent().find(\"ul.subnav\").slideDown('fast').show();$(this).parent().hover(function(){},function(){$(this).parent().find(\"ul.subnav\").fadeOut('fast');$(this).parent().find(\"span\").removeClass(\"bgmenuhove2\")})});$(\".srcolcontent\").jscroll({W:\"15px\",BgUrl:\"url(/static/img/ybb/images/s_bg.gif)\",Bg:\"right 0 repeat-y\",Bar:{Bd:{Out:\"#bcbcbc\",Hover:\"#ccc\"},Bg:{Out:\"-45px 0 repeat-y\",Hover:\"-58px 0 repeat-y\",Focus:\"-71px 0 repeat-y\"}},Btn:{btn:true,uBg:{Out:\"0 0\",Hover:\"-15px 0\",Focus:\"-30px 0\"},dBg:{Out:\"0 -15px\",Hover:\"-15px -15px\",Focus:\"-30px -15px\"}},Fn:function(){}});$(\"#centerhidden\").toggle(function(){scrolclear()},function(){scrolopen()});");
            SetPublic();
            set("top", loadHtml(Top));
        }

        [HttpGet]
        public virtual void Admin_Tab_List()
        {
            SetPublic();
            set("iframeheightwindow", ctx.Get("iframeheightwindow"));
            set("MaxPerPage", configsService.GetValue("max_list"));
            set("MaxHit", configsService.GetValue("max_page"));
            set("nowpage", ctx.GetInt("nowpage"));
            var limitkey = ctx.Get("limitkey");
            set("limitkey", limitkey);
            var limitclass = ctx.Get("limitclass");
            set("limitclass", limitclass);
            var LoadUrl = String.Empty;
            loadfun = ctx.Get("loadfun");
            switch (loadfun)
            {
                case "menulinkclist":
                    LoadUrl = to(new Qycms.MenuController().MenuLinkList) + "?mlid=" + ctx.GetInt("mlid") + "&loadfun=" + loadfun + "&limitkey=" + limitkey + "&limitclass=" + limitclass + "&isshow=" + ctx.Get("isshow");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().menulinklist));
                    break;

                case "menulinklist":
                    LoadUrl = to(new Qycms.MenuController().MenuLinkList) + "?loadfun=" + loadfun + "&limitkey=" + limitkey + "&limitclass=" + limitclass + "&isshow=" + ctx.Get("isshow");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().menulinklist));
                    break;

                case "languagelist":
                    LoadUrl = to(new Qycms.LanguageController().LanguageList) + "?loadfun=" + loadfun + "&limitkey=" + limitkey + "&limitclass=" + limitclass + "&lockin=" + ctx.Get("lockin") + "&isopen=" + ctx.Get("isopen") + "&isuptype=" + ctx.Get("isuptype");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().languagelist));
                    break;

                case "lanpacklist":
                    LoadUrl = to(new LanguageController().LngPackList) + "?loadfun=" + loadfun + "&lockin=" + ctx.Get("lockin") + "&lng=" + ctx.Get("lng") + "&typeid=" + ctx.Get("typeid") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().lanpacklist));
                    break;

                case "loglist":
                    LoadUrl = to(new LogController().LogList) + "?loadfun=" + loadfun + "&logusername=" + ctx.Get("logusername") + "&loguser=" + ctx.viewer.obj.Name;
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().loglist));
                    break;

                case "skinlist":
                    LoadUrl = to(new SkinController().SkinList) + "?loadfun=" + loadfun + "&lockin=" + ctx.Get("lockin") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().skinlist));
                    break;

                case "adverttypelist":
                    LoadUrl = to(new AdvertController().AdvertTypeList) + "?loadfun=" + loadfun + "&isclass=" + ctx.Get("isclass") + "&iscode=" + ctx.Get("iscode") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().adverttypelist));
                    break;

                case "advertlist":
                    LoadUrl = to(new AdvertController().AdvertList, ctx.GetInt("atid")) + "?loadfun=" + loadfun + "&isclass=" + ctx.Get("isclass") + "&istime=" + ctx.Get("istime") + "&adtype=" + ctx.Get("adtype") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().advertlist));
                    break;

                case "mangerlist":
                    LoadUrl = to(new UserController().AdminList) + "?loadfun=" + loadfun + "&isclass=" + ctx.Get("isclass") + "&inputclassid=" + ctx.Get("inputclassid") + "&powergroup=" + ctx.Get("powergroup") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().mangerlist));
                    break;

                case "articlelist":
                case "modelarticlelist":
                    LoadUrl = to(new ArticleController().ArticleList) + "?loadfun=" + loadfun + "&sid=" + ctx.Get("sid") + "&mid=" + ctx.Get("mid") + "&tid=" + ctx.Get("tid") + "&isbase=2&aid=" + ctx.Get("aid") + "&dlid=" + ctx.Get("dlid") + "&isclass=" + ctx.Get("isclass") + "&islink=" + ctx.Get("islink") + "&ishtml=" + ctx.Get("ishtml") + "&ismess=" + ctx.Get("ismess") + "&isorder=" + ctx.Get("isorder") + "&purview=" + ctx.Get("purview") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().articlelist));
                    break;

                case "memberlist":
                    set("tabmenubotton", loadHtml(new MenuBottonController().memberlist));
                    break;

                case "sitelist":
                    LoadUrl = to(new SiteController().SiteList) + "?limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().sitelist));
                    break;

                case "grouplist":
                    LoadUrl = to(new PowerGroupController().PowerGroupList) + "?" + "delclass=" + ctx.Get("delclass") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().grouplist));
                    break;

                case "modellist":
                    LoadUrl = to(new ModelController().ModelList) + "?loadfun=" + ctx.Get("loadfun") + "&isclass=" + ctx.Get("isclass") + "&lockin=" + ctx.Get("lockin") + "&isbase=" + ctx.Get("isbase") + "&istsn=" + ctx.Get("istsn") + "&isalbum=" + ctx.Get("isalbum") + "&isextid=" + ctx.Get("isextid") + "&issid=" + ctx.Get("issid") + "&isfgid=" + ctx.Get("isfgid") + "&islinkdid=" + ctx.Get("islinkdid") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().modellist));
                    break;

                case "modelattlist":
                    LoadUrl = to(new ModelController().ModelAttrList, ctx.GetInt("mid")) + "?loadfun=" + ctx.Get("loadfun") + "&isclass=" + ctx.Get("isclass") + "&isvalidate=" + ctx.Get("isvalidate") + "&issearch=" + ctx.Get("issearch") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().modelattlist));
                    break;

                case "recomlist":
                    LoadUrl = to(new RecomController().RecomList) + "?loadfun=" + ctx.Get("loadfun") + "&mid=" + ctx.Get("mid") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().recomlist));
                    break;

                case "acmessagelist":
                    LoadUrl = to(new ArticleController().MessageList) + "?loadfun=" + ctx.Get("loadfun") + "&did=" + ctx.Get("did") + "&isclass=" + ctx.Get("isclass") + "&isreply=" + ctx.Get("isreply") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().acmessagelist));
                    break;

                case "subjectlist":
                    LoadUrl = to(new SubjectController().SubjectList) + "?loadfun=" + ctx.Get("loadfun") + "&isclass=" + ctx.Get("isclass") + "&purview=" + ctx.Get("purview") + "&ismenu=" + ctx.Get("ismenu") + "&iswap=" + ctx.Get("iswap") + "&ishtml=" + ctx.Get("ishtml") + "&mid=" + ctx.Get("mid") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().subjectlist));
                    break;

                case "callinglist":
                    LoadUrl = to(new CallMainController().CallList) + "?loadfun=" + ctx.Get("loadfun") + "&isclass=" + ctx.Get("isclass") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().callinglist));
                    break;

                case "bbstypelist":
                    LoadUrl = to(new BbsController().BbsTypeList) + "?loadfun=" + ctx.Get("loadfun") + "&purview=" + ctx.Get("purview") + "&isclass=" + ctx.Get("isclass") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().bbstypelist));
                    break;

                case "bbsmainlist":
                    LoadUrl = to(new BbsController().BbsMainList) + "?loadfun=" + ctx.Get("loadfun") + "&btid=" + ctx.Get("btid") + "&upbid=" + ctx.Get("upbid") + "&isclass=" + ctx.Get("isclass") + "&istop=" + ctx.Get("istop") + "&noreply=" + ctx.Get("noreply") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().bbsmainlist));
                    break;

                case "formlist":
                    LoadUrl = to(new FormController().FormList) + "?loadfun=" + ctx.Get("loadfun") + "&isclass=" + ctx.Get("isclass") + "&ismenu=" + ctx.Get("ismenu") + "&isseccode=" + ctx.Get("isseccode") + "&iscount=" + ctx.Get("iscount") + "&purview=" + ctx.Get("purview") + "&isinputtime=" + ctx.Get("isinputtime") + "&ismail=" + ctx.Get("ismail") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().formlist));
                    break;

                case "messlist":
                    LoadUrl = to(new FormController().MessList) + "?loadfun=" + ctx.Get("loadfun") + "&isclass=" + ctx.Get("isclass") + "&fgid=" + ctx.Get("fgid") + "&isreply=" + ctx.Get("isreply") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().messlist));
                    break;

                case "formattlist":
                    LoadUrl = to(new FormController().ForMattList) + "?loadfun=" + ctx.Get("loadfun") + "&fgid=" + ctx.Get("fgid") + "&isclass=" + ctx.Get("isclass") + "&isvalidate=" + ctx.Get("isvalidate") + "&isline=" + ctx.Get("isline") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().formattlist));
                    break;

                case "fileadminlist":
                    LoadUrl = to(new FileController().FileList) + "?loadfun=" + ctx.Get("loadfun");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().fileadminlist));
                    break;
            }
            set("loadurl", LoadUrl);
        }

        [HttpGet]
        public virtual void Admin_Tab_List_Page()
        {
            SetPublic();
            set("iframeheightwindow", ctx.Get("iframeheightwindow"));
            set("MaxPerPage", configsService.GetValue("max_list"));
            set("MaxHit", configsService.GetValue("max_page"));
            set("nowpage", ctx.GetInt("nowpage"));
            var limitkey = ctx.Get("limitkey");
            set("limitkey", limitkey);
            var limitclass = ctx.Get("limitclass");
            set("limitclass", limitclass);
            var LoadUrl = String.Empty;
            loadfun = ctx.Get("loadfun");
            switch (loadfun)
            {
                case "templatelist":
                    LoadUrl = to(new TemplateController().TemplateList) + "?loadfun=" + loadfun;
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().loglist));
                    break;

                case "typelist":
                    LoadUrl = to(new TypeController().TypeList) + "?loadfun=" + ctx.Get("loadfun") + "&isclass=" + ctx.Get("isclass") + "&purview=" + ctx.Get("purview") + "&ismenu=" + ctx.Get("ismenu") + "&topid=" + ctx.Get("topid") + "&mid=" + ctx.Get("mid") + "&limitkey=" + ctx.Get("limitkey") + "&limitclass=" + ctx.Get("limitclass");
                    set("tablabel", loadHtml(TabLabel));
                    set("tabmenubotton", loadHtml(new MenuBottonController().typelist));
                    break;
            }
            set("loadurl", LoadUrl);
        }

        [HttpGet]
        public virtual void ClearCache()
        {
            target(ClearCacheDo);
            SetPublic();
            var digheight = ctx.Get("digheight");
            set("digheight", digheight);
        }

        [HttpPost]
        public virtual void ClearCacheDo()
        {
            var cleartype = ctx.PostInt("cleartype");
            YBBCache cacheService = YBBCache.GetCacheService();
            switch (cleartype)
            {
                case 1:
                    sys.Clear.ClearAll();
                    cacheService.FlushAll();
                    ctx.web.CookieClear();
                    SiteCache.Clear();
                    break;

                case 2:
                    sys.Clear.ClearAll();
                    cacheService.FlushAll();
                    ctx.web.CookieClear();
                    GC.Collect();
                    SiteCache.Clear();
                    break;

                case 3:
                    var folder = PathHelper.Map(strUtil.Join(sys.Path.Root, "Cache/Pic/"));
                    if (Directory.Exists(folder))
                    {
                        Directory.Delete(folder, true);
                    }
                    break;

                case 4:
                    sys.Clear.ClearAll();
                    cacheService.FlushAll();
                    ctx.web.CookieClear();
                    GC.Collect();
                    SiteCache.Clear();
                    HttpRuntime.UnloadAppDomain();
                    break;
            }
            db.RunSql("VACUUM");
            ctx.web.ResponseWrite("true");
            ctx.web.ResponseEnd();
        }

        [HttpGet]
        public virtual void FileCheck()
        {
            target(FileCheckDo);
            SetPublic();
            var digheight = ctx.Get("digheight");
            set("digheight", digheight);
            set("filedirlist.htmldir", configsService.GetValue("file_htmldir"));
            set("filedirlist.sitemapdir", configsService.GetValue("file_sitemapdir"));
            set("filedirlist.sqlbakdir", configsService.GetValue("file_sqlbakdir"));
            set("filedirlist.upfiledir", configsService.GetValue("upfile_dir"));
            set("filedirlist.cachedir", "Cache/");
        }

        [HttpPost]
        public virtual void FileCheckDo()
        {
            var builder = new MyStringBuilder();
            if (SystemFolderCheck(strUtil.Join(sys.Path.Root, configsService.GetValue("file_htmldir"))))
            {
                builder.Append("\"htmldir\":\"true\",");
            }
            else
            {
                builder.Append("\"htmldir\":\"false\",");
            }
            if (SystemFolderCheck(strUtil.Join(sys.Path.Root, configsService.GetValue("file_sitemapdir"))))
            {
                builder.Append("\"sitemapdir\":\"true\",");
            }
            else
            {
                builder.Append("\"sitemapdir\":\"false\",");
            }
            if (SystemFolderCheck(strUtil.Join(sys.Path.Root, configsService.GetValue("file_sqlbakdir"))))
            {
                builder.Append("\"sqlbakdir\":\"true\",");
            }
            else
            {
                builder.Append("\"sqlbakdir\":\"false\",");
            }
            if (SystemFolderCheck(strUtil.Join(sys.Path.Root, configsService.GetValue("upfile_dir"))))
            {
                builder.Append("\"upfiledir\":\"true\",");
            }
            else
            {
                builder.Append("\"upfiledir\":\"false\",");
            }
            if (SystemFolderCheck(strUtil.Join(sys.Path.Root, "Cache/")))
            {
                builder.Append("\"cachedir\":\"true\",");
            }
            else
            {
                builder.Append("\"cachedir\":\"false\",");
            }
            builder.Append("\"cachedirkey\":\"111111\"");
            ctx.web.ResponseWrite("{" + builder + "}");
            ctx.web.ResponseEnd();
        }

        public static bool SystemFolderCheck(string foldername)
        {
            var physicsPath = PathHelper.Map(strUtil.Join(sys.Path.Root, foldername));
            try
            {
                FileSystemObject.Create(physicsPath + "\\a.txt", FsoMethod.File);
                if (System.IO.File.Exists(physicsPath + "\\a.txt"))
                {
                    System.IO.File.Delete(physicsPath + "\\a.txt");
                    return true;
                }
                return false;
            }
            catch
            {
                return false;
            }
        }

        [HttpGet]
        public virtual void PassWord()
        {
            target(PassWordDo);
            SetPublic();
            set("iframename", ctx.Get("iframename"));
            set("digheight", ctx.GetInt("digheight"));
            var u = (User)ctx.viewer.obj;
            bind("memberinfo", u);
            var errconter = String.Empty;
            if (ctx.GetItem("errconter") != null)
            {
                errconter = ctx.GetItem("errconter").ToString();
            }
            set("errconter", errconter);
        }

        [HttpPost]
        public virtual void PassWordDo()
        {
            var password1 = ctx.Post("password1");
            var u = userService.GetByName(ctx.viewer.obj.Name);
            String hashedPwd = userService.HashPwd(password1, u.PwdSalt);
            var errconter = String.Empty;
            if (hashedPwd != u.Pwd)
            {
                errconter = "原密码错误！";
                ctx.SetItem("errconter", errconter);
                run(PassWord);
                return;
            }
            u.Pwd = userService.HashPwd(ctx.Post("password"), u.PwdSalt);
            u.Gender = ctx.PostInt("sex");
            u.RealName = ctx.Post("name");
            var result = u.update();
            logService.Add((User)ctx.viewer.obj, lang("management_password_log") + lang("log_extra_ok"), "{Id:" + u.Id + ", Name:'" + u.Name + "'}", this.GetType().FullName, ctx.Ip);
            ctx.web.SessionSet("calltitle", lang("management_password_message"));
            ctx.SetItem("digheight", ctx.PostInt("digheight"));
            ctx.SetItem("isfunction", "1");
            run(new AdminController().DigMessage);
        }

        [HttpGet]
        public virtual void ClearLog()
        {
            target(ClearLogDo);
            SetPublic();
            set("digheight", ctx.GetInt("digheight"));
            set("load", to(new AdminController().Load) + "?");
        }

        [HttpPost]
        public virtual void ClearLogDo()
        {
            var deltype = ctx.PostInt("deltype");
            if (deltype == 0)
            {
                var username = ctx.Post("username");
                User u = userService.GetByName(username);
                if (u == null)
                {
                    ctx.web.ResponseWrite("false");
                    ctx.web.ResponseEnd();
                    return;
                }
                SiteLog s = SiteLog.find(" UserId=:uid").set("uid", u.Id).first();
                s.delete();
            }
            else
            {
                SiteLog.deleteBatch("id>0");
            }
            logService.Add((User)ctx.viewer.obj, lang("clear_log_del_log") + lang("log_extra_ok"), ctx.Ip);
            ctx.web.ResponseWrite("true");
            ctx.web.ResponseEnd();
        }

        [NonVisit]
        public virtual void TabLabel()
        {
            loadfun = ctx.Get("loadfun");
            set("menutype", loadfun);
        }

        [NonVisit]
        public virtual void TabBotton()
        {
            loadfun = ctx.Get("loadfun");
            set("menutype", loadfun);
            switch (loadfun)
            {
                case "menulinkclist":
                    {
                        var list = Menulink.find(" topmlid=:t").set("t", 0).list();
                        bind("list", list);
                    }
                    break;

                case "advertlist":
                    {
                        var list = Advert_Type.find(" isclass=:i and lng=:l").set("i", 1).set("l", DefaultLng).list();
                        bind("list", list);
                    }
                    break;

                case "typelist":
                case "subjectlist":
                case "recomlist":
                    {
                        var list = Model.findAll();
                        bind("list", list);
                    }
                    break;

                case "seolinklist":
                case "seolinktypelist":

                    break;

                case "articlelist":
                    {
                        var list = Model.find("isbase=0 order by id asc").list();
                        bind("list", list);
                        var condition = " lng='" + DefaultLng + "' and upid = 0 ";
                        condition += " order by pid asc,id asc";
                        var list2 = wojilu.Apps.Qycms.Domain.TypeList.find(condition).list();
                        var list1 = new List<TypeList>();
                        foreach (var row in list2)
                        {
                            list1.Add(row);
                            type_list(ref list1, row);
                        }
                        bind("list1", list1);
                    }
                    break;
            }
            set("index", to(Index));
        }

        [NonVisit]
        public void type_list(ref List<TypeList> list, TypeList row)
        {
            var condition = " lng='" + DefaultLng + "' and upid = " + row.Id;
            DataPage<TypeList> list1 = null;
            Int32 maxperpage = ctx.PostInt("MaxPerPage");
            Int32 page_id = ctx.PostInt("page_id") + 1;
            String limitkey = ctx.Get("limitkey");
            String limitclass = ctx.Get("limitclass");
            if (strUtil.IsNullOrEmpty(limitkey)) limitkey = "pid";
            if (strUtil.IsNullOrEmpty(limitclass)) limitclass = "asc";
            condition += " order by " + limitkey + " " + limitclass + ",id asc";
            list1 = wojilu.Apps.Qycms.Domain.TypeList.findPage(condition, maxperpage);
            foreach (var row1 in list1.Results)
            {
                list.Add(row1);
                type_list(ref list, row1);
            }
        }

        [NonVisit]
        public virtual void Top()
        {
            User u = ctx.viewer.obj as User;
            var modelPowerGroup = PowerGroup.findById(u.GroupId);
            bind("powergroup", modelPowerGroup);
            set("adminurl", configsService.GetValue("domain"));
            set("softhttp", configsService.GetValue("domain"));
            set("lngs", DefaultLng);
            set("menuid", menuid);
            set("loadfun", loadfun);
            set("index", to(Index));
            set("logout", to(new AdminController().Logout));
            set("LanguageChange", to(LanguageChange));
        }

        [HttpGet]
        public virtual void LanguageChange()
        {
            var lng = ctx.Get("lng");
            var refererurl = ctx.web.PathReferrer;
            ctx.web.CookieSet("DefaultLng", lng);
            redirectUrl(refererurl);
        }

        [HttpPost]
        public virtual void SoftKey()
        {
            run(new HomeController().SoftKey);
        }

        [HttpGet]
        public virtual void UpcerFile()
        {
            SetPublic();
            set("load", to(new AdminController().Load) + "?");
            set("iframename", ctx.Get("iframename"));
            set("digheight", ctx.Get("digheight"));
            target(UpcerFileDo);
            set("softhttp", config.Instance.Site.SiteUrl);
            set("softversion", MvcConfig.Instance.Version);
            var isupfiletrue = String.Empty;
            if (ctx.GetItem("isupfiletrue") != null)
            {
                isupfiletrue = ctx.GetItem("isupfiletrue").ToString();
            }
            else
            {
                isupfiletrue = "true";
            }
            set("isupfiletrue", isupfiletrue);
        }

        [HttpPost]
        public virtual void UpcerFileDo()
        {
            if (ctx.HasUploadFiles)
            {
                var file = ctx.GetFileSingle();
            }
            var isupfiletrue = String.Empty;
            if (ctx.HasErrors)
            {
                isupfiletrue = "false";
                ctx.SetItem("isupfiletrue", isupfiletrue);
                run(UpcerFile);
                return;
            }
        }

    }
}